package org.fas.geom
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.geom.Matrix;
	import flash.geom.Point;
	/**
	 * Create a reflection Bitmap of source DisplayOjbect
	 * @author Jack
	 * 
	 */	
	public class Reflection extends Bitmap
	{
		public function Reflection(_source:DisplayObject=null)
		{
			this.source = _source;
		}
		public function set source(_source:DisplayObject):void{
			 //rever source from up to down 
		    var _bmd:BitmapData=new BitmapData(_source.width,_source.height,true,0);
		    var _mtx:Matrix=new Matrix();
		    _mtx.d=-1;
		    _mtx.ty=_bmd.height;
		    _bmd.draw(_source,_mtx);
			//create a new mask
		    var width:int=_bmd.width;
		    var height:int=_bmd.height;
		    _mtx=new Matrix();
		    _mtx.createGradientBox(width,height,0.5 * Math.PI);
		    var shape:Shape = new Shape();
		    shape.graphics.beginGradientFill(GradientType.LINEAR,[0,0],[0.9,0.2],[0,0xFF],_mtx)
		    shape.graphics.drawRect(0,0,width,height);
		    shape.graphics.endFill();
		    var mask__bmd:BitmapData=new BitmapData(width,height,true,0);
		    mask__bmd.draw(shape);
		    //final effect
		    _bmd.copyPixels(_bmd,_bmd.rect,new Point(0,0),mask__bmd,new Point(0,0),false);
			//put y below source
//		    this.y=_source.y+_source.height;
		    this.bitmapData = _bmd;
		}
	}
}